package com.example.dao.impl;

import com.example.dao.SubordinateCusDao;
import com.example.entity.customerAdmin.SubordinateCus;
import com.example.utils.BaseDao;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SubordinateCusDaoImpl implements SubordinateCusDao {
    @Override
    public List<SubordinateCus> selectAll (int page, int limit) {
        List<SubordinateCus> subordinateCusList=new ArrayList<> ();

        Object[] objects=new Object[2];
        objects[0]=page;
        objects[1]=limit;
        ResultSet select = BaseDao.select ("select * from subordinate_cus limit ?,?", objects);
        try {
            while (select.next ()){
                SubordinateCus subordinateCus=new SubordinateCus ();
                subordinateCus.setId (select.getInt ("id"));
                subordinateCus.setName (select.getString ("name"));
                subordinateCus.setStates (select.getString ("states"));
                subordinateCus.setCusType (select.getString ("cus_type"));
                subordinateCus.setPhone (select.getString ("phone"));
                subordinateCus.setCusAscription (select.getString ("cus_ascription"));
                subordinateCus.setRemarks (select.getString ("remarks"));
                subordinateCus.setContactUser (select.getString ("contact_user"));
                subordinateCusList.add (subordinateCus);
            }
        }catch (Exception e){
            e.printStackTrace ();
        }
        return subordinateCusList;
    }

    @Override
    public int getCount () {
        int i=-1;
        ResultSet select = BaseDao.select ("select count(1) getCount from subordinate_cus ", null);
        try {
            while (select.next ()){
                i=select.getInt ("getCount");
            }
        }catch (Exception e){
            e.printStackTrace ();
        }
        return i;
    }
}
